package com.macro.mall.operating.service.impl;

import com.macro.mall.operating.beans.LogRecord;
import com.macro.mall.operating.dao.ChartMapper;
import com.macro.mall.operating.service.ILogRecordService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * @author muzhantong
 * create on 2020/4/29 4:34 下午
 */
@Slf4j
@Service
public class DefaultLogRecordServiceImpl implements ILogRecordService {
    @Autowired
    private ChartMapper chartMapper;
//    @Resource
//    private LogRecordMapper logRecordMapper;

    @Override
//    @Transactional(propagation = Propagation.REQUIRES_NEW)
    public void record(LogRecord logRecord) {
        log.info("【logRecord】log={}", logRecord);
        chartMapper.createTable(getFakeChart());

        chartMapper.insert(logRecord);
        //throw new RuntimeException("sss");
//        logRecordMapper.insertSelective(logRecord);
    }

    @Override
    public List<LogRecord> queryLog(String bizNo, String type) {
        return new ArrayList<>();
    }

    @Override
    public List<LogRecord> queryLogByBizNo(String bizNo, String type, String subType) {
        return new ArrayList<>();
    }

    private static HashMap<String, Object> getFakeChart() {
        HashMap<String, Object> fakeChart = new LinkedHashMap<>();
        fakeChart.put("tableName", "operating_record_sys");
       // fakeChart.put("columns", Arrays.asList("id", "name", "email"));
        return fakeChart;
    }


}
